/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef _FMT_ARGS_PARSER_H_
#define _FMT_ARGS_PARSER_H_
#include <string>
#include <vector>
/*
The format strings are as follows:
I32: int32_t
U32: uint32_t
I64: int64_t
U64: uint64_t
f: double
s: const char *
S: std::string&
v: napi_value

They must start with '%'
For example:
napi_value value = JS_CallStaticMethodByName(env, "class1.class2.class3", "method1", "I32f", 1, 1.3);

parser:
fmt_str ::= fmt_str a_fmt
		| a_fmt
		;
a_fmt ::= INT32_FMT
		| UINT32_FMT
		| INT64_FMT
		| UINT64_FMT
		| DOUBLE_FMT
		| LOWER_S_FMT
		| UPPER_S_FMT
		| NAPI_VALUE_FMT
		;
lexical:
"I32" return INT32_FMT;
"I64" return INT64_FMT;
"U32" return UINT32_FMT;=
"U64" return UINT64_FMT;
"f" return DOUBLE_FMT;
"s" return LOWER_S_FMT; //const char*
"S" return UPPER_S_FMT; //const std::string*
"v" return NAPI_VALUE_FMT; //napi_value
' '
*/


class FMTArgsPaser
{
    const char* strToParse;
    const char* posBeingParsed;
    public:
        enum FMT_TOKEN_TYPE
        {
            UNKNOWN_FMT,
            INT32_FMT,
            INT64_FMT,
            UINT32_FMT,
            UINT64_FMT,
            DOUBLE_FMT,
            LOWER_S_FMT,
            UPPER_S_FMT,
            NAPI_VALUE_FMT,
            END_OF_FMT
        };
    private:
        FMT_TOKEN_TYPE GetNextToken();
    public:
        FMTArgsPaser(const char* str) {
            strToParse = str;
    }
    virtual ~FMTArgsPaser() {}
    //0: successful, otherwise: failed
    int Parse(std::vector<FMT_TOKEN_TYPE>& fmt_vec);
};




#endif